﻿using System.Collections.Generic;
using System.Linq;
using SellAndBuy.Application.Query.DTOs;

namespace SellAndBuy.Web.ViewModels
{
    /// <summary>
    /// View model for Ad List
    /// </summary>
    public class AdListViewModel : IPagedView<AdDTO>
    {
        private readonly IEnumerable<AdDTO> _ads;
        private readonly int _page;
        private readonly int _pageSize;

        /// <summary>
        /// Initializes a new instance of the view model
        /// </summary>
        public AdListViewModel(IEnumerable<AdDTO> ads, int page, int pageSize)
        {
            _ads = ads;
            _page = page;
            _pageSize = pageSize;
        }

        /// <summary>
        /// Whether it has previous page
        /// </summary>
        public bool HasPreviousPage
        {
            get { return _page > 0; }
        }

        /// <summary>
        /// Whether it has next page
        /// </summary>
        public bool HasNextPage
        {
            get { return _ads.Count() >= _pageSize; }
        }

        /// <summary>
        /// Previous Page
        /// </summary>
        public int PreviousPage
        {
            get { return _page - 1; }
        }

        /// <summary>
        /// Next Page
        /// </summary>
        public int NextPage
        {
            get { return _page + 1; }
        }

        /// <summary>
        /// Returns paged Ads
        /// </summary>
        public IEnumerable<AdDTO> PageItems
        {
            get { return _ads; }
        }

        /// <summary>
        /// Page size
        /// </summary>
        public int PageSize
        {
            get { return _pageSize; }
        }

    }
}